﻿using System;

namespace CoreHelper
{
    /// <summary>
    /// string 扩展方法
    /// </summary>
    public static partial class ExtensionMethod
    {
        #region string 扩展
        /// <summary>
        /// 是否是null或空字符串
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public static bool IsNullOrEmpty(this string str)
        {
            return StringHelper.IsNullOrEmpty(str);
        }

        /// <summary>
        /// 是否不为空字符串也不是null
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public static bool IsNotNullAndEmpty(this string str)
        {
            return StringHelper.IsNotNullAndEmpty(str);
        }

        /// <summary>
        /// 是否是整形
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public static bool IsInteger(this string str)
        {
            return StringHelper.IsInteger(str);
        }

        /// <summary>
        /// 判断字符串是否在几个字符之中
        /// </summary>
        /// <param name="str"></param>
        /// <param name="strs"></param>
        /// <returns></returns>
        public static bool IsIn(this string str, params string[] strs)
        {
            return StringHelper.IsIn(str, strs);
        }

        /// <summary>
        /// 截取字符串
        /// </summary>
        /// <param name="str">目标字符串</param>
        /// <param name="number">截取长度</param>
        /// <returns></returns>
        public static string InterceptString(this string str, int number)
        {
            return StringHelper.InterceptString(str, number);
        }


        /// <summary>
        /// 是否是浮点数
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsDouble(this string str)
        {
            return StringHelper.IsDouble(str);
        }

        /// <summary>
        /// 是否是手机号
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsCellPhone(this string str)
        {
            return StringHelper.IsCellPhone(str);
        }

        /// <summary>
        /// 是否是固话号
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsPhone(this string str)
        {
            return StringHelper.IsPhone(str);
        }

        /// <summary>
        /// 是否是邮箱地址
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsEmail(this string str)
        {
            return StringHelper.IsEmail(str);
        }

        /// <summary>
        /// 是否是中国公民身份证号
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsIDCard(this string str)
        {
            return StringHelper.IsIDCard(str);
        }
        #endregion

        #region 转换
        /// <summary>
        /// 字符串转整形
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int ToInteger(this string str)
        {
            return int.Parse(str);
        }

        /// <summary>
        /// 字符串转又精度浮点数
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static double ToNumber(this string str)
        {
            return double.Parse(str);
        }

        /// <summary>
        /// 字符串转日期
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(this string str)
        {
            return DateTime.Parse(str);
        }

        /// <summary>
        /// 格式转换
        /// </summary>
        /// <param name="str"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static string FormatWith(this string str, params object[] objs)
        {
            return string.Format(str, objs);
        }

        /// <summary>
        /// 首字母小写
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        /// 
        public static string ToCamel(this string str)
        {
            if (str.IsNullOrEmpty())
            {
                return str;
            }
            else
            {
                if (str.Length > 1)
                {
                    return str[0].ToString().ToLower() + str.Substring(1);
                }
                else
                {
                    return str.ToLower();
                }
            }
        }

        /// <summary>
        ///首字母大写
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string ToPascal(this string str)
        {
            if (str.IsNullOrEmpty())
            {
                return str;
            }
            else
            {
                if (str.Length > 1)
                {
                    return str[0].ToString().ToUpper() + str.Substring(1);
                }
                else
                {
                    return str.ToLower();
                }
            }
        }

        /// <summary>
        /// 得到大写
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string To32MD5(this string str)
        {
            return Encrypt.MD5.EncryptMD5(str);
        }

        #endregion

        #region 拼音
        /// <summary>
        /// 得到汉字的拼音字符串
        /// </summary>
        /// <param name="str">汉字</param>
        /// <returns></returns>
        public static string ToChineseSpell(this string str)
        {
            return StringHelper.GetChineseSpell(str);
        }

        /// <summary>
        /// 得到汉字字符串的首字母大写
        /// </summary>
        /// <param name="str">汉字</param>
        /// <returns></returns>
        public static string ToChineseIndex(this string str)
        {
            return StringHelper.GetChineseIndex(str);
        }
        #endregion
    }
}
